home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / sox / skel.c < prev    next >
C/C++ Source or Header  |  1994-08-01  |  3KB  |  138 lines

  1. /*
  2.  * July 5, 1991
  3.  * Copyright 1991 Lance Norskog And Sundry Contributors
  4.  * This source code is freely redistributable and may be used for
  5.  * any purpose.  This copyright notice must be maintained. 
  6.  * Lance Norskog And Sundry Contributors are not responsible for 
  7.  * the consequences of using this software.
  8.  */
  9.  
  10. /*
  11.  * Sound Tools skeleton file format driver.
  12.  */
  13.  
  14. #include "st.h"
  15.  
  16. /* Private data for SKEL file */
  17. typedef struct skelstuff {
  18.     int    rest;            /* bytes remaining in current block */
  19. } *skel_t;
  20.  
  21. IMPORT float volume, amplitude;
  22. IMPORT int summary, verbose;
  23.  
  24. /*
  25.  * Do anything required before you start reading samples.
  26.  * Read file header. 
  27.  *    Find out sampling rate, 
  28.  *    size and style of samples, 
  29.  *    mono/stereo/quad.
  30.  */
  31. skelstartread(ft) 
  32. ft_t ft;
  33. {
  34.     skel_t sk = (skel_t) ft->priv;
  35.  
  36.     /* If you need to seek around the input file. */
  37.     if (! ft->seekable)
  38.         fail("SKEL input file must be a file, not a pipe");
  39.  
  40.     /*
  41.      * If your format specifies or your file header contains
  42.      * any of the following information. 
  43.      */
  44.     ft->info.rate = 
  45.     ft->info.size = BYTE or WORD ...;
  46.     ft->info.style = UNSIGNED or SIGN2 ...;
  47.     ft->info.channels = 1 or 2 or 4;
  48.     ft->comment = any comment in file header.
  49. }
  50.  
  51. /*
  52.  * Read up to len samples from file.
  53.  * Convert to signed longs.
  54.  * Place in buf[].
  55.  * Return number of samples read.
  56.  */
  57.  
  58. skelread(ft, buf, len) 
  59. ft_t ft;
  60. long *buf, len;
  61. {
  62.     skel_t sk = (skel_t) ft->priv;
  63.     int abs;
  64.     float amp;
  65.     int done = 0;
  66.     
  67.     char c;
  68.     unsigned char uc;
  69.     short s;
  70.     unsigned short us;
  71.     long l;
  72.     unsigned long ul;
  73.     float f;
  74.     double d;
  75.  
  76.     for(; done < len; done++) {
  77.         if no more samples
  78.             break
  79.         get a sample
  80.         l = sample converted to signed long
  81.         *buf++ = l;
  82.     }
  83.     return done;
  84. }
  85.  
  86. /*
  87.  * Do anything required when you stop reading samples.  
  88.  * Don't close input file! 
  89.  */
  90. skelstopread(ft) 
  91. ft_t ft;
  92. {
  93. }
  94.  
  95. skelstartwrite(ft) 
  96. ft_t ft;
  97. {
  98.     skel_t sk = (skel_t) ft->priv;
  99.  
  100.     /* If you have to seek around the output file */
  101.     if (! ft->seekable)
  102.         fail("Output .skel file must be a file, not a pipe");
  103.  
  104.     /* If your format specifies any of the following info. */
  105.     ft->info.rate = 
  106.     ft->info.size = BYTE or WORD ...;
  107.     ft->info.style = UNSIGNED or SIGN2 ...;
  108.     ft->info.channels = 1 or 2 or 4;
  109.     /* Write file header, if any */
  110.     /* Write comment field, if any */
  111.     
  112. }
  113.  
  114. skelwrite(ft, buf, len) 
  115. ft_t ft;
  116. long *buf, len;
  117. {
  118.     skel_t sk = (skel_t) ft->priv;
  119.     register int datum;
  120.     int abs;
  121.     int done = 0;
  122.  
  123.     while(len--)
  124.         putc((*buf++ >> 24) ^ 0x80, ft->fp);
  125.     /* If you cannot write out all of the supplied samples, */
  126.     /*    fail("SKEL: Can't write all samples to %s", ft->filename); */
  127.     
  128. }
  129.  
  130. skelstopwrite(ft) 
  131. ft_t ft;
  132. {
  133.     /* All samples are already written out. */
  134.     /* If file header needs fixing up, for example it needs the */
  135.      /* the number of samples in a field, seek back and write them here. */
  136. }
  137.  
  138.